const initState = [{ id: '0001', name: 'Tom', age: 20 }]

export const types = {
  ADD_PERSON: 'add_person'
}

const reducer = (preState = initState, action) => {
  const { type, data } = action
  switch (type) {
    case types.ADD_PERSON:
      // return [data, ...preState]
      return preState.concat(data)

    default:
      return preState
  }
}

export default reducer

export const actions = {
  add: data => ({ type: types.ADD_PERSON, data })
}
